Valid for Sitecore
5.2, 5.3
What is the difference between AssertItemName, IsItemNameValid, and GetItemNameError?
Q:
The Sitecore.Data.Items.ItemUtil class includes three very similar methods. What is the difference between AssertItemName, IsItemNameValid, and GetItemNameError?
A:
- IsItemNameValid returns true if the given name is valid, false otherwise.
- GetItemNameError returns a string explaining why the given name is not valid.
- AssertItemName throws an exception if the given name is not valid.
AssertItemNameuses the other methods as follows:
if (!IsItemNameValid(name)) {
throw SomeException(GetItemNameError(name));
}